#include "stdafx.h"
#include "TableConfig.h"


TableConfig::TableConfig()
{
}

TableConfig::TableConfig(const TableConfig & from)
{
    name_ = from.name_;
    order_by_field_ = from.order_by_field_;
    fields_ = from.fields_;
	ope_fields_ = from.ope_fields_;
}

TableConfig::~TableConfig()
{
}

TableConfig & TableConfig::operator=(const TableConfig & from)
{
    name_ = from.name_;
    order_by_field_ = from.order_by_field_;
    fields_ = from.fields_;

    return *this;
}

void TableConfig::load(tinyxml2::XMLElement * element)
{
    if (element == nullptr)
    {
        return;
    }

    const char *name = element->Attribute("name");
	if (name)
	{
		name_ = name;
	}

    const char *order_by_field = element->Attribute("orderByField");
	if (order_by_field)
	{
		order_by_field_ = order_by_field;
	}

    auto fields_element = element->FirstChildElement("fields");
	if (fields_element != nullptr)
	{
		auto field_element = fields_element->FirstChildElement("field");

		while (field_element != nullptr)
		{
			Field field;
			field.load(field_element);
			fields_.push_back(field);

			field_element = field_element->NextSiblingElement("field");
		}
	}

	auto ope_fields_element = element->FirstChildElement("opeFields");
	if (ope_fields_element != nullptr)
	{
		auto field_element = ope_fields_element->FirstChildElement("field");

		while (field_element != nullptr)
		{
			Field field;
			field.load(field_element);
			ope_fields_.push_back(field);

			field_element = field_element->NextSiblingElement("field");
		}
	}
}
